Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbclient: support -o StrictHostKeyChecking #269

Merged
merged 18 commits into from
Apr 3, 2024

Conversation

stokito
Copy link
Contributor

@stokito stokito commented Dec 19, 2023

Fixes #226

@stokito
Copy link
Contributor Author

stokito commented Dec 24, 2023

I added other options that already have a flag. This will make interoperability with OpenSSH better because -K -J flags have a different meaning. So with the options we can help to write scripts that will work similarly.
Unfortunately this also makes code bigger but i hope that not so much. We can make a condition to compile only those options that doesn't have a flag or the flag meaning differs.
Still I believe that if someone have a place for Dropbear then they are probably ready to have some extra kilobytes.

@stokito stokito force-pushed the dbclient-StrictHostKeyChecking branch from 4b4c9d3 to ea40869 Compare December 24, 2023 13:39
dbclient -y is -o StrictHostKeyChecking=accept-new
dbclient -y -y is -o StrictHostKeyChecking=no
When executing:

    $ dbclient -i ~/id_rsa

then shell expands path to /home/user/id_rsa.
But when the key path is quoted or executed without a shell then this not happens:

    $ dbclient -i '~/id_rsa'
    Failed loading keyfile '~/id_rsa'

We already have a home dir expanding used for ~/.ssh/id_dropbear so reuse it.
@stokito stokito force-pushed the dbclient-StrictHostKeyChecking branch 2 times, most recently from 1896443 to 72412d0 Compare December 24, 2023 17:15
@stokito
Copy link
Contributor Author

stokito commented Dec 24, 2023

@Zepmann please test the StrictHostKeyChecking and BatchMode that you asked for in #224

The dbclient has flags that have equivalent opts:

 -b to -o BindAddress
 -i to -o IdentityFile
 -A to -o ForwardAgent
 -g to -o GatewayPorts
 -K to -o ServerAliveInterval
 -J to -o ProxyCommand

Note: in the  OpenSSH "-K Enables GSSAPI‐based authentication".
For interoperability use the -o ServerAliveInterval.

Note: in the OpenSSH the -J is same a -o ProxyJump.
For interoperability use the -o ProxyCommand.
The BatchMode same as PasswordAuthentication=no but it has more priority.
So you can't re-enable the PasswordAuthentication like in:

    dbclient -v -o BatchMode=yes -o PasswordAuthentication=yes example.com

It also disables the interactive confirmation when a host key changed.

Close mkj#224
@stokito stokito force-pushed the dbclient-StrictHostKeyChecking branch from 72412d0 to cad0484 Compare December 24, 2023 17:23
@Zepmann
Copy link

Zepmann commented Dec 27, 2023

Tested.

-oBatchMode=yes seems to work fine. 👍

The behavior of -oStrictHostKeyChecking=accept-new is not what is expected. With -oStrictHostKeyChecking=accept-new, the SSH client does not write the server's public key to known_hosts. If a known_hosts file does not exist, it will be created with 0 bytes of content. If known_hosts does exist, its content is not changed and the modification date is not updated, hinting that nothing is written/changed.

@stokito
Copy link
Contributor Author

stokito commented Dec 27, 2023

Right, so the dbclient should also store the hostkey to known_hosts without confirming.
I may try to fix that but in nearest time may not have a time for this.

@stokito
Copy link
Contributor Author

stokito commented Dec 29, 2023

@Zepmann I fixed the bug in a separate #271

I don't know if Matt will accept this PR but at least for that bug fix should be easier to pass review.
If you can, please merge that branch and re-test.
Thank you

@mkj
Copy link
Owner

mkj commented Dec 31, 2023

Thanks, this has been requested a bit. I still need to review the code.

One thing I notice, BatchMode disables password auth unconditionally. But it seems it should be allowed if using DROPBEAR_PASSWORD env var, or SSH_ASKPASS? (I can make the changes on top of this PR).

@stokito
Copy link
Contributor Author

stokito commented Dec 31, 2023

will add a fix in a minute

@Zepmann
Copy link

Zepmann commented Dec 31, 2023

BatchMode should prevent the need for any user interaction. All other program behavior should be as usual from an admin expectation perspective.

Just my 2 cents. Thanks for the work so far, @stokito and @mkj.

If the DROPBEAR_PASSWORD is set then use a password from it instead of asking for a user.
In the BatchMode this keeps working
@stokito
Copy link
Contributor Author

stokito commented Dec 31, 2023

I moved the batch mode cheking before the getpass() call.

@stokito
Copy link
Contributor Author

stokito commented Jan 6, 2024

Updated man page with new options

@HansH111
Copy link
Contributor

For multihop support you need to change multihop_passthrough_args() in cli-runopts.c and pass the -o values.

@stokito
Copy link
Contributor Author

stokito commented Feb 1, 2024

The options shouldn't be applied to jump servers. Or maybe the dropbear supports this? If you know how to make it please send a PR once this become merged.

@HansH111
Copy link
Contributor

HansH111 commented Feb 2, 2024

Maybe not, but I see -y -y being passed when using multihop in function
multihop_passthrough_args() in cli-runopts.c

@HansH111
Copy link
Contributor

HansH111 commented Feb 2, 2024

I just checked and removed the -y -y in that function and when I do a multihop now, it asks for confirmation because the hostkey is not in the trusted host file.

@stokito
Copy link
Contributor Author

stokito commented Feb 23, 2024

I tested how the PasswordAuth and BatchMode works with keyboard interactive auth. No issues with this.

The BatchMode=yes won't stuck in interactive auth but it will try it and fail only when the interactive asks for a user input. This is even better behavior that OpenSSH client have.
For example you can ssh to srv.us (free ssh tunnels provider) and it will ask for interactive mode but authorize immediately without asking.

When the PasswordAuth=no it will stuck in the interactive mode and wait for a user input.

I made a simple SSH server in Golang to test this. If you'll need it I'll share.

@HansH111
Copy link
Contributor

Added a pull request for -o BatchMode=yes and also passed it when multihop was selected.
I am not very experienced in git.... I have no idea how to put it in this pull request .

@stokito
Copy link
Contributor Author

stokito commented Feb 24, 2024

@HansH111 make an archive and send to me at [email protected]. You can't add commits to another one's PR

@mkj
Copy link
Owner

mkj commented Apr 1, 2024

I've pushed a few changes on top of this, and added in PR #281 from @HansH111 .

stricthostkeychecking=yes is changed a bit, previously it was asking whether to add.

@stokito
Copy link
Contributor Author

stokito commented Apr 1, 2024

Thank you, I'll retest today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support OpenSSH's StrictHostKeyChecking option with accept-new flag
4 participants